package com.sdp.khy.baotou.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sdp.core.bizc.vo.Result;
import com.sdp.khy.baotou.db.khy_price_info.entity.KhyPriceInfo;
import com.sdp.khy.baotou.db.khy_price_info.service.IKhyPriceInfoService;

@RestController
@RequestMapping("/KhyPriceInfoController")
public class KhyPriceInfoController {

	@Autowired
	private IKhyPriceInfoService khyPriceInfoService;
	
	@GetMapping(value = "/queryPriceInfo")
	public Result<?> queryPriceInfo() {
		LambdaQueryWrapper<KhyPriceInfo> queryWrapper = new LambdaQueryWrapper<>();
		KhyPriceInfo priceInfo = khyPriceInfoService.getOne(queryWrapper, false);
		return Result.ok(priceInfo == null ? new KhyPriceInfo() : priceInfo);
	}
	
	@PostMapping(value = "/save")
	@Transactional(rollbackFor=Exception.class)
	public Result<?> save(@RequestBody KhyPriceInfo priceInfo) {
		if(priceInfo==null) {
			return Result.error("信息为空");
		}
		if(StringUtils.isEmpty(priceInfo.getKeyId())) {
			khyPriceInfoService.save(priceInfo);
		}else {
			khyPriceInfoService.updateById(priceInfo);
		}
		return Result.ok(priceInfo);
	}
	
}
